//
//  GYMineHeadView.m
//  GYDemo
//
//  Created by mac on 2018/3/23.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "GYMineHeadView.h"
#import "Head.h"


@implementation HeaderChangeModel
@end
@interface GYMineHeadView()
{
    UILabel *phoneLabel;
    UILabel *levelLab;
    UIButton *loginBtn;
    UIView *levelBgView;
}
@property (nonatomic, strong) UIView *unLoginV;
@property (nonatomic, strong) UIView *loginedV;
@end

@implementation GYMineHeadView
-(UIView *)unLoginV
{
    if (!_unLoginV) {
        _unLoginV = [[UIView alloc] init];
        _unLoginV.frame = self.frame;
    }
    return _unLoginV;
}

-(UIView *)loginedV
{
    if (!_loginedV) {
        _loginedV = [[UIView alloc] init];
        _loginedV.frame = self.bounds;
    }
    return _loginedV;
}
#pragma mark - event
-(void)loginTap:(id)sender
{
    _callback();
}
-(instancetype)init
{
    if (self = [super init]) {
        self.width = WF_UI_VIEW_WIDTH;
        self.height = WFCGFloatY(60);
        self.userInteractionEnabled = YES;
        self.backgroundColor = Main_Color_Red;
        
        [self addSubview:self.unLoginV];
        [self addSubview:self.loginedV];
        
        phoneLabel = [[UILabel alloc] init];
        phoneLabel.font = SYSTEMFONT(18);
        phoneLabel.textAlignment = NSTextAlignmentLeft;
        phoneLabel.textColor = [UIColor whiteColor];
        [_loginedV addSubview:phoneLabel];
        
        loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [loginBtn setTitleColor:RGBACOLOR(0, 106, 255, 1) forState:UIControlStateNormal];
        [loginBtn setImage:[UIImage imageNamed:@"ljdl"] forState:UIControlStateNormal];
        loginBtn.titleLabel.font = SYSTEMFONT(15);
        [loginBtn addTarget:self action:@selector(loginTap:) forControlEvents:UIControlEventTouchUpInside];
        [_loginedV addSubview:loginBtn];
        
        levelBgView = [[UIView alloc] init];
        levelBgView.backgroundColor = [UIColor clearColor];
        [_loginedV addSubview:levelBgView];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)layoutSubviews
{
    [super layoutSubviews];
    loginBtn.frame = CGRectMake(_loginedV.width - WFCGFloatX(102), (_loginedV.height - WFCGFloatY(30))/2, WFCGFloatX(102), WFCGFloatY(30));
    levelBgView.frame = CGRectMake(WFCGFloatX(150), 0, self.width - WFCGFloatX(130 - 101 - 20), self.height);

    if ([[GYLoginViewModel shareInterface] loginstatus]) {
        levelBgView.hidden = NO;
        phoneLabel.text = [GYLoginViewModel shareInterface].loginInfoModel.nick_name;

        
        phoneLabel.frame = CGRectMake(WFCGFloatX(10),  (_loginedV.height - 30)/2.0f, 150, 30);
        
        
        for (UIView *view in levelBgView.subviews) {
            [view removeFromSuperview];
        }
    
        CGFloat levelImgWidth = WFCGFloatX(14);
        CGFloat levelImgHeight = WFCGFloatY(14);
        CGFloat levelImgSpace = WFCGFloatX(5);
        
        for (NSInteger i = 0; i <3; i++) {
            UIImageView *levelImgV = [[UIImageView alloc] init];
            levelImgV.image = [UIImage imageNamed:@"xydj_a"];
            levelImgV.frame = CGRectMake((levelImgWidth + levelImgSpace) * i, (_loginedV.height - levelImgHeight)/2.0f, levelImgWidth, levelImgHeight);
            [levelBgView addSubview:levelImgV];
        }
        
        levelLab = [[UILabel alloc] init];
        levelLab.font = SYSTEMFONT(12);
        levelLab.textAlignment = NSTextAlignmentLeft;
        levelLab.textColor = [UIColor whiteColor];
        [levelBgView addSubview:levelLab];
        
        levelLab.text =@"Lv.3";
        levelLab.frame = CGRectMake(WFCGFloatX(10) + (3* levelImgWidth +9), 0, WFCGFloatX(100), _loginedV.height);
        
        loginBtn.hidden = YES;
    }else{
        loginBtn.hidden = NO;
        phoneLabel.text = @"未登录";
        levelLab.hidden = YES;
        levelBgView.hidden = YES;
        phoneLabel.frame = CGRectMake(WFCGFloatX(10), 0, WFCGFloatX(100), _loginedV.height);
    }

}
@end
